package com.wyy.controller;

import com.wyy.beans.Role;
import com.wyy.common.Result;
import com.wyy.service.RoleService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @PostMapping("/role")
    @RequiresRoles("admin")
    public Result<Role> addRole(@RequestBody Role role){
        return roleService.addRole(role);
    }

    @PutMapping("/role")
    @RequiresRoles("admin")
    public Result<Role> updateRole(@RequestBody Role role){
        return roleService.updateRole(role);
    }

    @DeleteMapping("/role/{rid}")
    @RequiresRoles("admin")
    public Result<Role> deleteRole(@PathVariable long rid){
        return roleService.deleteRole(rid);
    }

    @GetMapping("/role/{rid}")
    public Result<Role> getRoleById(@PathVariable long rid){
        return roleService.getRoleById(rid);
    }

}
